/*
 * wrote by casper 2007.12.1
 */
package ants.p2p.security.sockets;

import java.io.ObjectInputStream;
import java.net.SocketTimeoutException;
import java.io.InputStream;
import java.io.IOException;

public class ObjectSocketInputStream {
	ObjectInputStream in;

	public ObjectSocketInputStream(InputStream socketInputStream) throws IOException {
		boolean bNotInited = true;
		while (bNotInited) {
			try {
				this.in = new ObjectInputStream(socketInputStream);
				bNotInited = false;
			} catch (SocketTimeoutException e) {
			}
		}
	}

	//we use this function to filter SocketTimeout Exception
	public int readInt() throws IOException {
		while (true) {
			try {
				return this.in.readInt();
			} catch (SocketTimeoutException e) {
			}
		}
	}

	public Object readObject() throws IOException, ClassNotFoundException {
		while (true) {
			try {
				return this.in.readObject();
			} catch (SocketTimeoutException e) {
			}
		}
	}
}
